<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"
              encoding="utf-8"
              media-type="text/html"
              doctype-public="-//W3C//DTD HTML 4.01//EN"
              doctype-system="http://www.w3.org/TR/xtml4/strict.dtd" />

  <xsl:template match="/">
    <xsl:apply-templates select="content/post" />
  </xsl:template>

  <xsl:template match="post">
    <xsl:call-template name="item" />
  </xsl:template>

  <xsl:template name="item">
    <xsl:param name="class">post announcement</xsl:param>
    <xsl:param name="height">64</xsl:param>
    <div class='{$class}' data-post-id='{@id}'>
      <p class='signature'>
        <span title='Дата публикации'>
          <span class='ui-icon ui-icon-calendar' /><xsl:value-of select="@date" />
        </span>
        <xsl:apply-templates select="autor" />
        <span class='lcomment' title='Последний комментарий' data-get-last='{//urls/base}/comments/getlast/{@id}'>
          <span class='ui-icon ui-icon-comment' /><xsl:value-of select="@comments" />
        </span>
      </p>
      <h2>
        <a href='{//urls/base}/posts/post/{@id}' class='link'>
          <xsl:value-of select="title" />
        </a>
      </h2>
      <a href='{//urls/base}/posts/post/{@id}' class='link'>
        <div class='text'>
          <xsl:if test="@photo">
            <xsl:attribute name="style">
              <xsl:value-of select="concat('min-height:', $height, 'px;')" />
            </xsl:attribute>
            <img src='{@photo}?s={$height}' alt='' align='left' />
          </xsl:if>
          <xsl:value-of select="content" disable-output-escaping="yes" />
        </div>
      </a>
      <xsl:apply-templates select="tags" />
      <xsl:if test="@can-remove=1">
        <xsl:if test="not(tags)"><br /></xsl:if>
        <p>
          <span class='ui-icon ui-icon-trash' />&#160;<a href='#' class='del-post'>Удалить</a>
        </p>
      </xsl:if>
    </div>
    <xsl:if test="@can-remove=1">
      <div class='{$class} sentenced invisible'>
        <label class='errorMessage'>Пост удален</label>&#160;
        <span class='ui-icon ui-icon-close' />&#160;<a href='#' class='restore-post'>Отменить</a>
      </div>
    </xsl:if>
  </xsl:template>

  <xsl:template match="post/autor">
    <a href='{//urls/base}/user/profile/{@login}' class='link aprofile'>
      <img src='{@avatar}?s=16' alt='' />
      <xsl:value-of select="." />
    </a>
  </xsl:template>

  <xsl:template match="post/tags">
    <p class='tags' title='Теги'>
      <xsl:if test="0&lt;count(tag)">
        <span class='ui-icon ui-icon-tag' />
        <xsl:apply-templates select="tag" />
      </xsl:if>
    </p>
  </xsl:template>

  <xsl:template match="post/tags/tag">
    <a href='#' class='tag' data-tag-id='{@id}'>
      <xsl:value-of select="." />
    </a>&#160;
  </xsl:template>

  <xsl:template name="form">
    <xsl:param name="action" />
    <form class='{$action}-post invisible' action='{//urls/base}/posts/{$action}' method='post'>
      <xsl:choose>
        <xsl:when test="@id">
          <input type='hidden' name='pid' value='{@id}' />
        </xsl:when>
        <xsl:when test="@type">
          <input type='hidden' name='post[type]' value='{@type}' />
        </xsl:when>
      </xsl:choose>
      <p title='Заголовок'>
        <input type='text' name='post[title]' id='post-title' maxlength='100' />
      </p>
      <xsl:if test="@type='news'">
        <input type='hidden' name='mainImage' id='main-image-num' />
        <div>
          <div class='ui-state-default illustration' title='Добавить фото'>
            <div id='no-image' />
            <span class='ui-icon hidden' />
          </div>
        </div>
      </xsl:if>
      <textarea name='post[content]' />
      <p title='Теги'>
        <span class='ui-icon ui-icon-tag' />
        <input type='text' id='post-tags' maxlength='100' />
        <a href='#' class='ui-icon ui-icon-plus' id='add-tag' title='добавить' />
      </p>
    </form>
  </xsl:template>

</xsl:stylesheet>
